home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / cpp112.zoo / src / global.h < prev    next >
C/C++ Source or Header  |  1994-07-07  |  8KB  |  266 lines

  1. /*---------------------------------------------------------------------*\
  2. |                                    |
  3. | CPP -- a stand-alone C preprocessor                    |
  4. | Copyright (c) 1993 Hacker Ltd.        Author: Scott Bigham    |
  5. |                                    |
  6. | Permission is granted to anyone to use this software for any purpose    |
  7. | on any computer system, and to redistribute it freely, with the    |
  8. | following restrictions:                        |
  9. | - No charge may be made other than reasonable charges for repro-    |
  10. |     duction.                                |
  11. | - Modified versions must be clearly marked as such.            |
  12. | - The author is not responsible for any harmful consequences of    |
  13. |     using this software, even if they result from defects therein.    |
  14. |                                    |
  15. | global.h -- global definitions                    |
  16. \*---------------------------------------------------------------------*/
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20.  
  21. #ifndef __MINT__
  22. # ifdef __STDC__
  23. # define __PROTO(x) x
  24. # else
  25. # define __PROTO(x) ()
  26. # endif
  27. #endif
  28.  
  29. typedef struct macro {
  30.   struct macro *next;        /* for free-list chaining */
  31.   int nargs;
  32.   unsigned int flags;
  33. #define MAGIC    0x0001        /* system special #define */
  34. #define MAGIC2    0x0002        /* as above, but not always visible */
  35. #define HASARGS    0x0004        /* check for arguments */
  36. #define MARKED    0x0008        /* used for recursive #definitions */
  37. #define UNDEF    0x0010        /* -U argument */
  38.   struct token *argnames;
  39.   struct token *m_text;
  40. } Macro;
  41.  
  42. typedef struct token {
  43.   struct token *next;
  44.   union {
  45.     char *out_of_line;
  46.     char inline[8];
  47.   } _txt;
  48.   union {
  49.     char *out_of_line;
  50.     char inline[4];
  51.   } _ws;
  52.   long val;
  53.   unsigned int hashval;
  54.   char type;
  55.   char subtype;
  56.   unsigned int flags;
  57. #define BLUEPAINT    0x0001    /* not available for expansion */
  58. #define UNS_VAL        0x0002    /* value is unsigned */
  59. #define STRINGIZE_ME    0x0004    /* stringized macro arg */
  60. #define CONCAT_NEXT    0x0008    /* concatenate this token with next token */
  61. #define TRAIL_SPC    0x0010    /* add spc to prevent accidental token merge */
  62. #define UNPAINT_ME    0x0020    /* see expand() and expand_tlist() */
  63. #define INLINE_TXT    0x0040    /* text of token is inline */
  64. #define INLINE_WS    0x0080    /* whitespace is inline */
  65. } Token, *TokenP;
  66.  
  67. /* accessor macros to get at the inlined strings */
  68. #define token_txt(Tp)    \
  69.     (((Tp)->flags & INLINE_TXT) ? (Tp)->_txt.inline : (Tp)->_txt.out_of_line)
  70. #define token_ws(Tp)    \
  71.     (((Tp)->flags & INLINE_WS) ? (Tp)->_ws.inline : (Tp)->_ws.out_of_line)
  72.  
  73. typedef struct hash {
  74.   struct hash *next;
  75.   union {
  76.     char inline[8];
  77.     char *out_of_line;
  78.   } _id;
  79.   Macro *data;
  80.   unsigned int flags;
  81. #define INLINE_KEY    0x0001    /* text of key is inline */
  82. } Hash;
  83.  
  84. /* token types */
  85. #define UNKNOWN        1
  86. #define DONT_CARE    2
  87. #define EOL        3
  88. #define NUMBER        4
  89. #define FP_NUM        5
  90. #define ID        6
  91. #define STR_CON        7
  92. #define CHAR_CON    8
  93. #define UNARY_OP    9
  94. #define MUL_OP        10
  95. #define ADD_OP        11
  96. #define SHIFT_OP    12
  97. #define REL_OP        13
  98. #define EQ_OP        14
  99. #define B_AND_OP    15
  100. #define B_XOR_OP    16
  101. #define B_OR_OP        17
  102. #define L_AND_OP    18
  103. #define L_OR_OP        19
  104. #define LPAREN        20
  105. #define RPAREN        21
  106. #define COMMA        22
  107. #define INC_NAM        23
  108. #define POUND        24
  109. #define TOK_CAT        25
  110. #define MACRO_ARG    26
  111. #define EOF_        27
  112. #define STOP        28
  113. #define UNMARK        29
  114.  
  115. /* tokenizer modes */
  116. #define NORMAL        0    /* default behavior */
  117. #define INCLUDE_LINE    1    /* return <filename.h> as a single token */
  118. #define IF_EXPR        2    /* interpret defined(IDENTIFIER) */
  119. #define SLURP        4    /* ignore preprocessor directives */
  120.  
  121. /* types of synchronization lines */
  122. #define SL_NONE   0        /* no sync line */
  123. #define SL_NORMAL 1        /* default style:  # 15 "fred.c" */
  124. #define SL_LINE   2        /* preproc style:  #line 15 "fred.c" */
  125.  
  126. #if defined(__MINT__) || defined(__GNUC__)
  127. #define PATH_SEP '/'
  128. #else
  129. #define PATH_SEP '\\'
  130. #endif
  131.  
  132. #define STDIN_NAME "standard input"
  133.  
  134. #define streq(s,t) (strcmp((s),(t))==0)
  135. #define nelems(arr) (sizeof(arr)/sizeof((arr)[0]))
  136.  
  137. /* Global variables and functions from each file */
  138.  
  139. /* comment.c */
  140. char *suck_ws __PROTO((char *, TokenP));
  141.  
  142. /* define.c */
  143. void do_define __PROTO((void));
  144. void do_undefine __PROTO((void));
  145. int macro_eq __PROTO((Macro *, Macro *));
  146.  
  147. /* hash.c */
  148. Macro *lookup __PROTO((char *, unsigned int));
  149. unsigned int hash_id __PROTO((char *, char **));
  150. void hash_add __PROTO((char *, unsigned int, Macro *));
  151. void hash_clean_undef __PROTO((void));
  152. void hash_free __PROTO((void));
  153. void hash_remove __PROTO((char *, unsigned int));
  154. void hash_setup __PROTO((void));
  155.  
  156. /* if_expr.c */
  157. int if_expr __PROTO((void));
  158.  
  159. /* include.c */
  160. void do_include __PROTO((void));
  161. extern unsigned long include_level;
  162.  
  163. /* input.c */
  164. /* HSC #defines the following if and only if it is in a mode that gives
  165.    external identifiers more than 7 characters of significance.  If your
  166.    compiler can handle long identifiers, feel free to delete this
  167.    #defin'ition. */
  168. #ifndef __HSC_LONGNAMES__
  169. #define expand_rest_of_line    E_rol
  170. #endif
  171. TokenP tokenize_string __PROTO((char *));
  172. char *getline __PROTO((void));
  173. char *rest_of_line __PROTO((void));
  174. void expand_rest_of_line __PROTO((void));
  175. void flush_line __PROTO((void));
  176. extern char *cur_file;
  177. extern unsigned long last_line, this_line, next_line;
  178.  
  179. /* macro.c */
  180. Macro *mk_Macro __PROTO((void));
  181. void free_Macro __PROTO((Macro *));
  182. TokenP expand_tlist __PROTO((TokenP));
  183. void expand __PROTO((TokenP, Macro *));
  184. extern char *magic_words[];
  185. extern int N_MWORDS;
  186.  
  187. /* main.c */
  188. extern FILE *inf;
  189. extern FILE *outf;
  190. extern char *argv0;
  191. extern char **I_list;
  192. extern char date_string[], time_string[];
  193. extern int nerrs;
  194. extern int sl_style, keep_comments, do_trigraphs, ansi, w_bad_chars,
  195.        w_nest_cmts, f_cpp_cmts, w_bad_concat;
  196. extern int in_config_file, Argc_end;
  197. extern int fluff_mode;
  198. void do_cmdline_arg __PROTO((char *));
  199. void do_all_cmdline_args __PROTO((void));
  200.  
  201. /* pound.c */
  202. void cond_setup __PROTO((void));
  203. void cond_shutdown __PROTO((void));
  204. void directive __PROTO((void));
  205. void endif_check __PROTO((void));
  206. extern int *if_sp;
  207. #define COND_TRUE    1
  208. #define COND_NESTED    2
  209. #define cond_true() ((if_sp[-1]&(COND_TRUE|COND_NESTED))==COND_TRUE)
  210.  
  211. /* process.c */
  212. void process_file __PROTO((char *));
  213. void sync_line __PROTO((int));
  214. void synchronize __PROTO((void));
  215.  
  216. /* token.c */
  217. TokenP mk_Token __PROTO((void));
  218. void clear_txt __PROTO((TokenP));
  219. void clear_ws __PROTO((TokenP));
  220. void set_txt __PROTO((TokenP, const char *));
  221. void set_ws __PROTO((TokenP, const char *));
  222. void set_txt_n __PROTO((TokenP, const char *, int));
  223. TokenP copy_tlist __PROTO((TokenP));
  224. TokenP copy_token __PROTO((TokenP));
  225. TokenP merge_tokens __PROTO((TokenP, TokenP));
  226. TokenP mk_eol __PROTO((void));
  227. TokenP mk_stopper __PROTO((void));
  228. TokenP mk_unmarker __PROTO((TokenP));
  229. TokenP mk_printable __PROTO((const char *));
  230. TokenP token __PROTO((void));
  231. int get_mode __PROTO((void));
  232. void change_mode __PROTO((int, int));
  233. void flush_tokenizer __PROTO((void));
  234. void free_tlist __PROTO((TokenP));
  235. void free_token __PROTO((TokenP));
  236. void print_token __PROTO((TokenP));
  237. void push_tlist __PROTO((TokenP));
  238. void set_mode __PROTO((int));
  239. void tok_shutdown __PROTO((void));
  240. TokenP exp_token __PROTO((void));
  241. TokenP _one_token __PROTO((void));
  242. void _tokenize_line __PROTO((void));
  243. #ifdef DEBUG
  244. void dump_token __PROTO((TokenP));
  245. void dump_tlist __PROTO((TokenP));
  246. void dump_pushback __PROTO((void));
  247. #endif
  248.  
  249. /* utils.c */
  250. void fatal __PROTO((const char *, ...));
  251. void bugchk __PROTO((const char *, ...));
  252. void warning __PROTO((const char *, ...));
  253. void error __PROTO((const char *, ...));
  254. char *copy_filename __PROTO((char *, int));
  255. #ifndef __GNUC__
  256. char *strdup __PROTO((const char *));
  257. #endif
  258. FILE *xfopen __PROTO((const char *, const char *));
  259. #define NEWBUFSIZ ((size_t)4096)
  260. void *mallok __PROTO((size_t));
  261. void *reallok __PROTO((void *, size_t));
  262. char *grow __PROTO((char **, size_t *, char *, int));
  263.  
  264. /* ztype.c */
  265. void Z_type_init __PROTO((void));
  266.